<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <select id="city">
        <option value="1">北京</option>
        <option value="2">上海</option>
        <option value="3">广州</option>
        <option value="4">深圳</option>
    </select>

    <input type="text" id="username" autofocus>

    <script>
        let oCity = document.getElementById('city');
        let oUsername = document.getElementById('username');

        oCity.onchange = function(){
            alert(oCity.value);
        }

        oUsername.onfocus = function(){
            oUsername.value = "hello";
        }

        oUsername.onblur = function(){
            oUsername.value = "bye bye";
        }

        oUsername.oninput = function(){
            if(oUsername.value.length > 5){
                alert("超出5个了");
            }
        }
    </script>
</body>
</html>